/**
 * @file WarGamesApplication.java
 * @author ApertureScience
 */
package aperturescience.wargames;
import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.resource.Directory;
import org.restlet.routing.Router;

import aperturescience.resources.ActionEngineResource;
import aperturescience.resources.ActionResource;
import aperturescience.resources.ActionsResource;
import aperturescience.resources.PatientResource;
import aperturescience.resources.PatientsResource;

/**
 * This class links the URIs with the classes that access the database.
 */
public class WarGamesApplication extends Application  {
	
	public static final String couchdburl = "http://plato.cs.virginia.edu:5984/";
    public static final String databasename = "group4db";
    //public static final String databasename = "mjp2af";
	
	/**
	 * Creates root Reslet to receive and route all incoming requests to respective resources, based on URL.
	 */
    @Override
    public Restlet createInboundRoot()
    {
        // Create a router Restlet that defines routes.
        Router router = new Router(getContext());
        System.out.println(router.getContext().toString());
        
        // URLs for resources regarding patients.
        router.attach("/patients", PatientsResource.class);
        router.attach("/patients/{patientId}", PatientResource.class);
        
        // URLs for resources regarding actions.
        router.attach("/actions", ActionsResource.class);
        router.attach("/actions/{actionId}", ActionResource.class);
        
        // URLs for the "state machine".
        //router.attach("/applyAction", ActionEngineResource.class); //works for POST
        router.attach("/patients/{patientId}/{actionId}", ActionEngineResource.class); //works for PUT
        
        // Attach the HTML interface
        router.attach("/", new Directory(getContext(), "war:///"));
        
        // Give our router to the server to start getting requests.
        return router;
    }
}
